//
//  ZCInvolvedContentCell.m
//  zctx
//
//  Created by apple on 15/12/28.
//  Copyright © 2015年 sanliang. All rights reserved.
//

#import "ZCInvolvedContentCell.h"

@implementation ZCInvolvedContentCell


+(instancetype)cellWithInvolvedContentCell:(UITableView *)tableView{
    
    static NSString *IDcell = @"contentCell";
    ZCInvolvedContentCell *cell = [tableView dequeueReusableCellWithIdentifier:IDcell];
    if (!cell) {
        cell = [[ZCInvolvedContentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:IDcell];
    }
    return cell;
}

- (void)awakeFromNib {
    // Initialization code
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.textView.textColor = [UIColor colorWithHexString:@"#404040"];
    CGSize size = CGSizeMake(320,2000); //设置一个行高上限
    NSDictionary *attribute = @{NSFontAttributeName: self.deatailButton.titleLabel.font};
    CGFloat labelWidth = [self.deatailButton.titleLabel.text boundingRectWithSize:size options: NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading attributes:attribute context:nil].size.width;
    
    self.deatailButton.imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth+3, 0, -labelWidth-3);
    self.deatailButton.titleEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 15);
    
    [self.deatailButton setTitleColor:[UIColor colorWithHexString:@"#03ab9e"] forState:UIControlStateNormal];
    
}

-(void)setIndexPaths:(NSIndexPath *)indexPaths{
    _indexPaths = indexPaths;
    
}
- (IBAction)ClickButton:(UIButton *)sender {
   
    if (_delegate && [_delegate respondsToSelector:@selector(ClickZCInvolvedContentCellButton:)]) {
        [_delegate ClickZCInvolvedContentCellButton:self.indexPaths];
    }
    NSLog(@"sender");
}


-(void)setModel:(ZCInvolvedDetailsModelContent *)model{
    _model = model;
    
    BOOL isnull = [NSString isNull:model.content];
    if (isnull == YES) {
        model.content = @"";
    }
    self.textView.text = model.content;
    NSLog(@"model.content = %@",model.content);
    
    CGFloat count = self.textView.font.lineHeight * 5;
    CGSize size = CGSizeMake(SCREEN_WIDTH-18*2,2000); //设置一个行高上限
    NSDictionary *attribute = @{NSFontAttributeName: self.textView.font};
    CGFloat labelHeight = [self.textView.text boundingRectWithSize:size options: NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading attributes:attribute context:nil].size.height;
    NSLog(@"size = %f,lableheight = %f",count , labelHeight);
    
    if (labelHeight<count) {
        [self.deatailButton removeFromSuperview];
        [self.textView updateConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView.centerY).with.offset(0);
            make.left.equalTo(self.contentView.left).with.offset(18);
            make.right.equalTo(self.contentView.right).with.offset(-18);
            make.top.equalTo(self.contentView.top).with.offset(12);
        }];
    }
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
